import requests
import lxml.etree as le
import xlwt
wb = xlwt.Workbook()
sh = wb.add_sheet('小节名称&链接')
sh.write(0,0,"title")
sh.write(0,1,"url")

url = 'https://www.runoob.com/html/html-tutorial.html'
x = '//div[@id="leftcolumn"]/a/text()'
y = '//div[@id="leftcolumn"]/a/@href'
content = requests.get(url).content

contentx = le.HTML(content)
title = contentx.xpath(x)
urls = contentx.xpath(y)

urls_list = []
for urls1 in urls:
    if urls1[0]=="/":
        urls1 = "https://www.runoob.com"+urls1
    else:
        urls1 = "https://www.runoob.com/" + urls1
    urls_list.append(urls1)


for i in range(1,75):
    sh.write(i,0,title[i-1])
    sh.write(i,1,urls_list[i-1])

wb.save('E:/Lagou/text.xls')


